/**
 * 响应数据
 */
export interface ApiResponse<T = null> {
  code: Code
  message: string
  data: T
}

/**
 * 状态码
 */
export enum Code {
  // 成功
  SUCCESS = 0,
  // 失败
  ERROR = 1,
  // 验证失败
  ERROR_VALIDATE = 2,
  // 未登录 或登录已失效
  NOT_LOGIN = 401,
}

/**
 * 请求分页公共数据
 */
export interface PageParams {
  /**
   * 页码
   */
  page?: number
  /**
   * 每页数量
   */
  page_size?: number
}

/**
 * 通用查询
 */
export interface WhereParams<T> {
  where?: T
  op?: Record<keyof T, OpModel>
}

export type CommonPageParams<T> = PageParams & WhereParams<T>

export enum OpModel {
  EQ = '=',
  NOT_EQ = '!=',
  IN = 'in',
  NOT_IN = 'not_in',
  BETWEEN = 'between',
  NOT_BETWEEN = 'not_between',
  LIKE = 'like',
  GT = '>',
  GE = '>=',
  LT = '<',
  LE = '<=',
  NULL = 'null',
  NOT_NULL = 'not_null',
}

/**
 * 分页响应数据
 */
export interface PageResponse<T = null> {
  total: number
  data: Array<T>
  current_page: number
  page_size: number
}
